home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.4)
-
- from test import test_support
- import os
- import struct
- import stat
- import sys
-
- try:
- import signal
- oldhandler = signal.signal(signal.SIGXFSZ, signal.SIG_IGN)
- except (ImportError, AttributeError):
- pass
-
- size = 0x9502F900L
- name = test_support.TESTFN
- if sys.platform[:3] == 'win' or sys.platform == 'darwin':
- test_support.requires('largefile', 'test requires %s bytes and a long time to run' % str(size))
- else:
- f = open(test_support.TESTFN, 'wb')
-
- try:
- f.seek(0x80000001L)
- f.write('x')
- f.flush()
- except (IOError, OverflowError):
- f.close()
- os.unlink(test_support.TESTFN)
- raise test_support.TestSkipped, 'filesystem does not have largefile support'
-
- f.close()
-
- def expect(got_this, expect_this):
- if test_support.verbose:
- print '%r =?= %r ...' % (got_this, expect_this),
-
- if got_this != expect_this:
- if test_support.verbose:
- print 'no'
-
- raise test_support.TestFailed, 'got %r, but expected %r' % (got_this, expect_this)
- elif test_support.verbose:
- print 'yes'
-
-
- if test_support.verbose:
- print 'create large file via seek (may be sparse file) ...'
-
- f = open(name, 'wb')
-
- try:
- f.write('z')
- f.seek(0)
- f.seek(size)
- f.write('a')
- f.flush()
- if test_support.verbose:
- print 'check file size with os.fstat'
-
- expect(os.fstat(f.fileno())[stat.ST_SIZE], size + 1)
- finally:
- f.close()
-
- if test_support.verbose:
- print 'check file size with os.stat'
-
- expect(os.stat(name)[stat.ST_SIZE], size + 1)
- if test_support.verbose:
- print 'play around with seek() and read() with the built largefile'
-
- f = open(name, 'rb')
-
- try:
- expect(f.tell(), 0)
- expect(f.read(1), 'z')
- expect(f.tell(), 1)
- f.seek(0)
- expect(f.tell(), 0)
- f.seek(0, 0)
- expect(f.tell(), 0)
- f.seek(42)
- expect(f.tell(), 42)
- f.seek(42, 0)
- expect(f.tell(), 42)
- f.seek(42, 1)
- expect(f.tell(), 84)
- f.seek(0, 1)
- expect(f.tell(), 84)
- f.seek(0, 2)
- expect(f.tell(), size + 1 + 0)
- f.seek(-10, 2)
- expect(f.tell(), size + 1 - 10)
- f.seek(-size - 1, 2)
- expect(f.tell(), 0)
- f.seek(size)
- expect(f.tell(), size)
- expect(f.read(1), 'a')
- f.seek(-size - 1, 1)
- expect(f.read(1), 'z')
- expect(f.tell(), 1)
- finally:
- f.close()
-
- if test_support.verbose:
- print 'play around with os.lseek() with the built largefile'
-
- f = open(name, 'rb')
-
- try:
- expect(os.lseek(f.fileno(), 0, 0), 0)
- expect(os.lseek(f.fileno(), 42, 0), 42)
- expect(os.lseek(f.fileno(), 42, 1), 84)
- expect(os.lseek(f.fileno(), 0, 1), 84)
- expect(os.lseek(f.fileno(), 0, 2), size + 1 + 0)
- expect(os.lseek(f.fileno(), -10, 2), size + 1 - 10)
- expect(os.lseek(f.fileno(), -size - 1, 2), 0)
- expect(os.lseek(f.fileno(), size, 0), size)
- expect(f.read(1), 'a')
- finally:
- f.close()
-
- if hasattr(f, 'truncate'):
- if test_support.verbose:
- print 'try truncate'
-
- f = open(name, 'r+b')
-
- try:
- f.seek(0, 2)
- expect(f.tell(), size + 1)
- newsize = size - 10
- f.seek(newsize)
- f.truncate()
- expect(f.tell(), newsize)
- f.seek(0, 2)
- expect(f.tell(), newsize)
- newsize -= 1
- f.seek(42)
- f.truncate(newsize)
- expect(f.tell(), 42)
- f.seek(0, 2)
- expect(f.tell(), newsize)
- f.seek(0)
- f.truncate(1)
- expect(f.tell(), 0)
- expect(len(f.read()), 1)
- finally:
- f.close()
-
-
- os.unlink(name)
-